/*
 * Copyright (c) 2017. Visionet and/or its affiliates. All right reserved.
 * VISIONET PROPRIETARY/CONFIDENTIAL.
 */
package com.visionet.jumper.core.domain.search.filter;

import com.visionet.jumper.core.domain.search.enumdata.JoinType;
import com.visionet.jumper.core.exception.runtime.FrameworkException;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author TC.Ubuntu
 * @since 2017/7/10.
 */
public abstract class JoinTableCondition {

	private Map<String, String> joinCondition = new HashMap<>();

	private String joinTableName;

	private String joinAliasName;

	private JoinType joinType;

	protected void join(String joinTableName, String joinAliasName) {
		if(StringUtils.isBlank(joinTableName) ||  StringUtils.isBlank(joinAliasName)) {
			throw new FrameworkException("连接表名或别名不能为空");
		}
		this.joinTableName = joinTableName;
		this.joinAliasName = joinAliasName;
	}

	/**
	 *
	 * @param mainColName 主表列名
	 * @param joinColName 连接表列名
	 */
	public JoinTableCondition addJoinColumn(String mainColName, String joinColName) {
		if(StringUtils.isBlank(mainColName) || StringUtils.isBlank(joinColName)) {
			throw new FrameworkException("连接条件不能为空");
		}
		this.getJoinCondition().put(mainColName, joinColName);
		return this;
	}

	public String getJoinTableName() {
		return joinTableName;
	}

	public void setJoinTableName(String joinTableName) {
		this.joinTableName = joinTableName;
	}

	public String getJoinAliasName() {
		return joinAliasName;
	}

	public void setJoinAliasName(String joinAliasName) {
		this.joinAliasName = joinAliasName;
	}

	public Map<String, String> getJoinCondition() {
		return joinCondition;
	}

	public void setJoinCondition(Map<String, String> joinCondition) {
		this.joinCondition = joinCondition;
	}

	public JoinType getJoinType() {
		return joinType;
	}

	public void setJoinType(JoinType joinType) {
		this.joinType = joinType;
	}
}
